#pip install pymongo[srv]
import pymongo
import json
import pandas as pd
class pygo:
    client =pymongo.MongoClient("mongodb+srv://ltsjim:ltsjack123@cluster0.x6bey.mongodb.net/myFirstDatabase?retryWrites=true&w=majority")
    db = client.test
    print(client.list_database_names())
    mydb=client['web_data']
    mycol=mydb['text']
    mycol.insert({'fo':2})
    print(client.list_database_names())
    print(client['sample_mflix'])

class MongoBase:
    def __init__(self,collection):
        self.collection=collection#需要传参写入对应库名的集合名，集合名不需要提前定义
        self.OpenDB()
    def OpenDB(self):
        self.con =pymongo.MongoClient("mongodb+srv://ltsjim:ltsjack123@cluster0.x6bey.mongodb.net/admin?retryWrites=true&w=majority")
        self.db=self.con['test']#这个是要操作的库名
        self.collection=self.db[self.collection]
    def closeDB(self):
        self.con.close()
if __name__ == '__main__':
    Df_Mongo = MongoBase('Df_Mongo')
    print(Df_Mongo.db)



    # Df_Mongo.collection.insert_many(json.loads(df_test.T.to_json()).values())
    # Df_Mongo.closeDB()